from waveapi import events
from waveapi import model
from waveapi import robot
from waveapi import document
from waveapi import robot_abstract 
import logging


def OnParticipantsChanged(properties, context):

	added= properties['participantsAdded']
	logging.debug(dir(context))
	for p in added:
		logging.debug(dir(p))
		user=str(p)
		Notify(context,user)

def OnRobotAdded(properties, context):
	root_wavelet = context.GetRootWavelet()
	root_wavelet.CreateBlip().GetDocument().SetText("Im alive!")

def Notify(context,user):
	root_wavelet = context.GetRootWavelet()
	root_wavelet.CreateBlip().GetDocument().SetText("Hello "+user)

if __name__ == '__main__':
	myRobot = robot.Robot('textilizer', image_url='http://textilizer.appspot.com/assets/icon.png', version='1.1', profile_url='http://textilizer.appspot.com/')
	myRobot.RegisterHandler(events.WAVELET_PARTICIPANTS_CHANGED, OnParticipantsChanged)
	myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
	myRobot.Run()

